#!/bin/python

import socket
import time
def senddata(fin,socket,userid="test",proid=12345):
    header = userid+"@"+str(proid)
    source=""
    for line in fin:
        source+=line
    header+="@"+str(len(source))     # Inform the server, the length of the source to be sent.
    socket.send(header)
    s=socket.recv(1024)
    if int(s)==1:
        socket.send(source)
        s = socket.recv(1024) 
        print str(s)
    else:
        print "Service is not available."
    socket.close()   
def test():
    s = socket.socket()
    s.connect(('localhost',1234))
    f = open('simplebin2.c')
    senddata(f,s)
    
if __name__=="__main__":
    test()
